<?php

/**
 * Banner Class
 *
 * @category    botenmarkt
 * @package     library
 * @subpackage  domainObjects
 * 
 * @author    valerii lazarevych <valeriy.fremar@gmail.com>
 * @copyright fremar ltd.
 * 
 * @license   default
 * @version   4:47:33 PM | Jan 13, 2012
 */

/**
 * Object model of the site banner
 */
class   Banners_domainObject      extends     domainObject
{
    /**
     * Banner name
     * 
     * @var string
     */
    public $name             =      null;
    
    /**
     * Is banner now online?
     * 
     * @var bool
     */
    public $banStatus        =      0;
    
    /**
     * Size of banner image height x widht
     * 
     * @var string
     */
    public $size             =      null;
    
    /**
     * Code of banner position on page
     * 
     * @var int
     */
    public $position         =      null;


    /**
     * Is banner introduce by code or pic url
     * 
     * @var bool
     */
    public $is_code          =      0;
    
    /**
     * Banner url link
     * 
     * @var string
     */
    public $url              =      0;

    /**
     * Banner image url
     * @var string
     */
    public $picture_url      =      null;
    
    /**
     * Banner javascript code
     * 
     * @var string
     */
    public $code             =      null;
    
    /**
     * Unix time stamp banner begin to show
     * 
     * @var string
     */
    public $fromDate        =      null;
    
    /**
     * Unix time stamp banner will be stoped to show
     * 
     * @var string
     */
    public $toDate          =      null;
    
    /**
     * Banner url by default
     * 
     * @var string  |   url
     */
    protected static    $baseUrl        =       null;
    
    /**
     * Banner picture url by default
     * 
     * @var string  |   url
     */
    protected static    $basePicture    =       null;

    
    
    /**
     * Get banner url
     * 
     * @return string   |   url
     */
    protected function bannerUrl()
    {
        return $this->url   ?: self::$baseUrl;
    }
    
    /**
     * Get banner picture url
     * 
     * @return string   |   url
     */
    protected function bannerPicture()
    {
        return $this->picture_url   ?: self::$basePicture;
    }

        /**
     * Output banner as an image link or javascript code
     *
     * @return string
     */
    public function bannerLink()
    {
        if ($this->is_code){
            
            return html_entity_decode($this->code);
            
        } else {            // if ($this->getUrl())
            return '<a href="'. $this->bannerUrl() .'" target="_blank">
                    <img src="/images/banners/'. $this->bannerPicture() .'" /></a>';
        }                            
    }
}

?>
